<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');	 
class Verifylogin_tester extends CI_Controller {
    function __construct()
    {
        parent::__construct();
	$this->load->model('Login_m');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->model('Readcsvlogin_m');
        $this->load->model('Comment_m');
    } 
    function index()
    {
        
        if($this->check_tester()==0)
        {
            $data['error_login']="ユーザーまたはパースワードが違い!";
            $data['query']=$this->Login_m->select_mg();
            $session_data = $this->session->userdata('links');
            $links=$session_data['test_sub_title'].":".$session_data['manager_name'].":"
                    .$session_data['start_time'].":".$session_data['end_test_time'];
            redirect('login_tester/readLink/'.$links,'refresh');
        }   
        else if($this->check_tester()==1)
        {
            $session_data_ex = $this->session->userdata('logged_in_te');
            $id_ex = $session_data_ex['id_te'];
            $test_sub_title=$session_data_ex['test_sub_title'];
            $this->Login_m->update_online_te($id_ex,$test_sub_title,1);
            redirect('tester/test','refresh');
        }
    }
    function check_tester()
    {
        $id = $this->input->post('txtID');
        $password = $this->input->post('txtPass');
        $manager_name=$this->input->post('txtManagerName');
        $test_sub_title=$this->input->post('txtTestSubTitle');
        $start_time=$this->input->post('txtStartTime');
        $end_test_time=$this->input->post('txtEndTestTime');
        $test_title=$this->input->post('txtTestTitle');
        $result_te = $this->Login_m->login_tester($id, $password,$test_sub_title);
        if($this->Login_m->select_online_flag_te($id,$test_sub_title)->num_rows()>0/*||$this->Login_m->select_offline_flag_te($id,$test_sub_title)->num_rows()>0*/)
        {
            $sess_array = array('manager_name'=>$manager_name,'test_sub_title' => $test_sub_title,
                    'start_time'=>$start_time,'end_test_time'=>$end_test_time,'test_title'=>$test_title);
            $this->session->set_userdata('links', $sess_array);
            return 0;
        }
        if($result_te)
        {
            $sess_array_tester = array();
            foreach($result_te as $row_te)
            {
                $sess_array_tester = array('id_te' => $row_te->id_te,'manager_name'=>$manager_name,'test_sub_title' => $test_sub_title,
                    'start_time'=>$start_time,'end_test_time'=>$end_test_time,'test_title'=>$test_title);
                $this->session->set_userdata('logged_in_te', $sess_array_tester);
            }
            return 1;
        }
        else
        {
            $sess_array = array('manager_name'=>$manager_name,'test_sub_title' => $test_sub_title,
                    'start_time'=>$start_time,'end_test_time'=>$end_test_time,'test_title'=>$test_title);
            $this->session->set_userdata('links', $sess_array);
            return 0;
        }
    }
}